<?php

require_once("main.php");


require_once(DIR_LIB."VsUsers".DIR_SEP."vsuser.php");


// Form Processing
//===============================================================================================
if(isset($_REQUEST['mode']) && ($_REQUEST['mode']=='edit')) {

	if(isset($_REQUEST['submit'])) {
		if(($_POST['passwd1']!='') && ($_POST['passwd1']==$_POST['passwd2'])) {
			$authData =  VsAuthData::makeUserById($_POST['user_id'], 'admin_logins');
			$authData->setPassword($_POST['passwd1']);

			//echo $_POST['passwd1']."<br/>";
			//echo $_POST['passwd2']."<br/>";
			//exit;
		}

		$userEdit = VsUser::makeUserFromForm($_POST, 'admin_logins', 'admin_info');

		$userEdit->save();

		header("Location: ".$_SERVER['PHP_SELF']);
	}

}


// Init Model
//===============================================================================================

if(isset($_REQUEST['mode']) && ($_REQUEST['mode']=='edit')) {
	$userEdit = VsUser::makeUserById($_REQUEST['id'], 'admin_logins', 'admin_info');
}
else {
	$listUsers = VsUser::makeUsers('admin_logins', 'admin_info');
}



// Init VIEW
//===============================================================================================

require_once(dirname(__FILE__).DIR_SEP."templates".DIR_SEP."XCart".DIR_SEP."xcart_wrapper.php");
require_once(dirname(__FILE__).DIR_SEP."templates".DIR_SEP."XCart".DIR_SEP."xcart_menu.php");

if(isset($_REQUEST['mode']) && ($_REQUEST['mode']=='edit')) {
	require_once(dirname(__FILE__).DIR_SEP."templates".DIR_SEP."XCart".DIR_SEP."xcart_admin_useredit.php");

	$page->setTitle("Admin Users Edit Form");

	$formUsers = new XCartAdminUserEdit($page, $userEdit);
}
else {
	require_once(dirname(__FILE__).DIR_SEP."templates".DIR_SEP."XCart".DIR_SEP."xcart_users.php");

	$page->setTitle("Admin Users");

	$formUsers = new XCartUsers($page, $listUsers);

}

$menu = new XCartVerticalMenu();

$wrapper = new XCartWrapper($page);
$wrapper->addMenu($menu->show());
$wrapper->addCentralWdget($formUsers->show());

$page->addWidget($wrapper);

$page->show();


// EXIT
//==================================================================================================


?>
